package Rainwater.controller;

import Rainwater.Service.AnalysisService;
import Rainwater.Service.PointService;
import Rainwater.baen.R;
import Rainwater.baen.vo.AnalysisCreateVo;
import Rainwater.baen.vo.AnalysisSFigVo;
import Rainwater.baen.vo.AnalysisPointVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author cfy
 * @date 2024/10/15
 **/
@RequestMapping("/rainwater/page")
@Controller
public class AnalysisController {
    @Autowired
    private AnalysisService analysisService;
    @Autowired
    private PointService pointService;
    private R r = new R();
    @GetMapping("/analysis")
    public ModelAndView pageIndex(){
        ArrayList<AnalysisPointVo> lists = pointService.getPointNames();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("data_analysis");
        modelAndView.addObject("points",lists);
        return modelAndView;
    }
    @ResponseBody
    @PostMapping("/analysis/figData")
    public R pageStaticFig(@RequestBody String fun){
        AnalysisSFigVo figVo = new AnalysisSFigVo();
        figVo.setUsers(analysisService.userFig());
        figVo.setPoint(analysisService.pointFig());
        figVo.setTem(analysisService.TemFig());
        figVo.setAir(analysisService.airFig());
        figVo.setWind(analysisService.windFig());
        return r.success(figVo);
    }

    /**
     * 图标选择生成
     * @param createVo
     * @return
     */
    @ResponseBody
    @PostMapping("/analysis/createFig")
    public R pageCreateFig(@RequestBody AnalysisCreateVo createVo){
        Map<String, Integer> map = analysisService.waterFig(createVo);
        return r.success(map);
    }
}
